package com.thinksns.sociax.t4.android.event;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.thinksns.sociax.android.R;
import com.thinksns.sociax.component.CustomTitle;
import com.thinksns.sociax.component.LeftAndRightTitle;
import com.thinksns.sociax.t4.android.ThinksnsAbscractActivity;
import com.thinksns.sociax.unit.SociaxUIUtils;

/**
 * Created by zhiyicx on 2017/5/10.
 */

public class EventCastActivity extends ThinksnsAbscractActivity {

    private EditText event_cast_et;
    private EditText event_cast_detail_et;
    public static final int RESULT_CODE = 1230;
    public static final String CAST = "cast";
    public static final String CAST_DETAIL = "cast_detail";

    @Override
    public String getTitleCenter() {
        return "费用详情";
    }

    @Override
    public CustomTitle setCustomTitle() {
        return new LeftAndRightTitle(this,R.drawable.img_back,"保存");
    }

    @Override
    public View.OnClickListener getLeftListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SociaxUIUtils.hideSoftKeyboard(EventCastActivity.this,event_cast_et);
                SociaxUIUtils.hideSoftKeyboard(EventCastActivity.this,event_cast_detail_et);
                finish();
            }
        };
    }

    @Override
    public View.OnClickListener getRightListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SociaxUIUtils.hideSoftKeyboard(EventCastActivity.this,event_cast_et);
                SociaxUIUtils.hideSoftKeyboard(EventCastActivity.this,event_cast_detail_et);
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString(CAST,event_cast_et.getText().toString());
                bundle.putString(CAST_DETAIL,event_cast_detail_et.getText().toString());
                intent.putExtras(bundle);
                setResult(RESULT_CODE,intent);
                finish();
            }
        };
    }

    @Override
    protected int getLayoutId() {
        return R.layout.event_cast_activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

    private void initView(){
        event_cast_et = (EditText) findViewById(R.id.event_cast_et);
        event_cast_detail_et = (EditText) findViewById(R.id.event_cast_detail_et);
    }

    private void initData(){
        Intent intent = getIntent();
        String price = intent.getStringExtra(EventCastActivity.CAST);
        String tips = intent.getStringExtra(EventCastActivity.CAST_DETAIL);

        if(!TextUtils.isEmpty(price)) {
            event_cast_et.setText(price);
            event_cast_et.setSelection(price.length());
        }
        if(!TextUtils.isEmpty(tips)) {
            event_cast_detail_et.setText(tips);
        }
    }
}
